package ar.edu.itba.it.poo

class Interval(start: Int, stop: Int, step: Int) extends Iterable[Int] {
    require(Math.signum(stop - step) == Math.signum(step))
    require((stop - start) % step == 0)

    def this(start: Int, stop: Int) = this(start, stop, 1)

    def at(index: Int): Int = {
        require(index >= 0)
        
        val l = List[String]()
        l.iterator
        
        return start + step * index
    }

    override def toString() = "(" + start + ", " + step + ", " + stop + ")"

//    def indexOf(element: Int): Option[Int] = this.zipWithIndex.first(_ == element)

//    def includes(element: Int): Boolean = indexOf(element).isDefined
    
    override def iterator: Iterator[Int] = new Iterator[Int] {
    	var current = start
    	override def hasNext = current != stop
    	override def next(): Int = if (hasNext) { current += step; current } else Iterator.empty.next  
    }
}

object IntervalTest extends Application {
	val interval1 = new Interval(1, 10)
	
	println(interval1)
//	println("index of 5: " + interval1.indexOf(5))
//	println("index of 20: " + interval1.indexOf(15))
//	println("includes 20: " + interval1.includes(20))
//	println("includes 12: " + interval1.includes(11))
}